package cn.itcast.order.web;

import cn.itcast.order.pojo.Order;
import cn.itcast.order.service.OrderService;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    @SentinelResource("hot")
    @GetMapping("{orderId}")
    public Order queryOrderByUserId(@PathVariable("orderId") Long orderId,
            @RequestHeader(value = "X-Request-other", required = false) String other) {
        log.info("header is:{}", other);
        // 根据id查询订单并返回
        return orderService.queryOrderById(orderId);
    }

    @GetMapping("query")
    public String queryOrder() {
        orderService.queryGoods();
        log.info("查询订单");
        return "查询订单成功";
    }

    @GetMapping("save")
    public String saveOrder() {
        orderService.queryGoods();
        log.info("新增订单");
        return "save ok";
    }

    @GetMapping("update")
    public String updateOrder() {
        return "update ok";
    }
}
